<template>
  <div>
 <div>
      <div style="margin-top: 15px;">
        <el-col :span="6">
          <el-input placeholder="请输入名称进行查询" v-model="getByName" class="input-with-select">

            <el-button slot="append" icon="el-icon-search" @click="selByName">查询</el-button>
          </el-input>
        </el-col>
        <el-button type="infor" style="position: relative;left: 850px;" @click="addSeverity">新增<i class="el-icon-upload el-icon--right"></i></el-button>
      </div>
    </div>

    <el-table :data="getSeverityByPage" style="width: 100%">
      <el-table-column prop="severityId" label="编号"></el-table-column>
      <el-table-column prop="severityDesc" label="严重程度"></el-table-column>
      <el-table-column prop="moduleState" label="状态"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-link icon="el-icon-edit" @click="changeSeverity(scope.row.severityId)" type="primary">修改</el-link>
          <el-link icon="el-icon-edit" @click="delSeverity(scope.row.severityId)" type="primary">删除</el-link>
          <!-- <el-link icon="el-icon-edit" @click="changemessage(scope.row)" type="primary"> -->


          <el-link icon="el-icon-edit" type="primary" @click="closeSeverity(scope.row.severityId)">
            {{scope.row.moduleState=='有效'?'禁用':'启用'}}
          </el-link>



          <!-- </el-link> -->
        </template>
      </el-table-column>

    </el-table>

    <el-pagination fixed @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pages.current"
      :page-sizes="[1, 2, 3, 4]" :page-size="pages.size" layout="total, sizes, prev, pager, next, jumper" :total="pages.total">
    </el-pagination>

    <el-dialog title="添加严重程度" :visible.sync="dialogVisible" width="30%">
      <el-form>
        <el-input type="text" placeholder="严重程度" v-model="severityName"></el-input>
        <!-- <textarea cols="48" rows="2" placeholder="项目描述" v-model="changeprojectinfo.projectDesc"></textarea> -->

 </el-form>
 <!-- <el-select v-model="value" placeholder="请选择项目">
     <el-option
       v-for="item in Allproject"
       :key="item.projectId"
       :label="item.projectName"
       :value="item.projectId">
     </el-option>
   </el-select> -->
      <span slot="footer" class="dialog-footer">
        <!-- <el-button @click="dialogVisible = false">取 消</el-button> -->
        <el-button type="primary" @click="sureadd">确 定</el-button>
      </span>
    </el-dialog>


    <el-dialog title="修改严重程度" :visible.sync="dialogVisible2" width="30%">
      <el-form>
        <el-input type="text" placeholder="严重程度" v-model="changeSeverityName"></el-input>
        <!-- <textarea cols="48" rows="2" placeholder="项目描述" v-model="changeprojectinfo.projectDesc"></textarea> -->


      </el-form>
      <span slot="footer" class="dialog-footer">
        <!-- <el-button @click="dialogVisible = false">取 消</el-button> -->
        <el-button type="primary" @click="surechange">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  export default{
    name:"severity",
    data(){
      return{
        getSeverityByPage:[],
        pages:{},
        dialogVisible:false,
         dialogVisible2:false,
        severityName:"",
        changeSeverityName:"",
        sevsrityId:0,
        getByName:""
        // Allproject:[],
        // value:""
      }
    },
    methods:{
      getAllSeverity(current,size){
          this.$http.post("defectSeverity/getAllSeverity",{"current":current,
                                                            "size":size,
                                                           }).then(resp=>{
            this.getSeverityByPage=resp.data.data.records
            this.pages=resp.data.data
          })
      },
      handleSizeChange(val) {

        this.pages.size = val
        this.getAllSeverity(this.pages.num, val)
      },
      handleCurrentChange(val) {
        this.pages.current = val
        this.getAllSeverity(val, this.pages.size)
      },
      addSeverity(){
        // this.$http.get("projectInfo/getAllProject").then(resp=>{
        //   this.Allproject=resp.data.data
        // })
        this.dialogVisible=true;

      },
      sureadd(){
        this.$http.post("defectSeverity/addSeverity",{"severityDesc":this.severityName,
                                                      "accountName":JSON.parse(localStorage.getItem("loginUser")).accountName

        }).then(resp=>{
          if(resp.data.code==200){
            this.$message({
              message: resp.data.message,
              type: 'success'
            })
            this.dialogVisible=false
             this.getAllSeverity(1,3)
             this.severityName=null
          }else{
            this.$message.error(resp.data.message)
            this.severityName=null
          }


        })
      },
      closeSeverity(sid){
        this.$http.get("defectSeverity/closeSeverity",{
          params:{
            "severityId":sid
          }
        }).then(resp=>{
          if(resp.data.code==200){
            this.$message({
              message: resp.data.message,
              type: 'success'
            })
          }else{
            this.$message.error(resp.data.message)
          }
          this.getAllSeverity(1,3)
        })
      },
      changeSeverity(sid){
        this.$http.get("defectSeverity/checkSeverity",{
          params:{
            "severityId":sid
          }
        }).then(resp=>{
          if(resp.data.code==200){
            this.dialogVisible2=true
            this.sevsrityId=sid

          }else{
            this.$message.error(resp.data.message)
              
          }

        })
      },
      surechange(sid){
        this.$http.get("defectSeverity/changeSeverity",{
          params:{
            "severityId":this.sevsrityId,
            "accountName":JSON.parse(localStorage.getItem("loginUser")).accountName,
            "severityDesc":this.changeSeverityName
          }
        }).then(resp=>{
          if(resp.data.code==200){
            this.$message({
              message: resp.data.message,
              type: 'success'
            })
             this.changeSeverityName=null
             this.getAllSeverity(1,3)
             this.dialogVisible2=false
          }else{
            this.$message.error(resp.data.message)
             this.changeSeverityName=null
          }
          
        })
      },
      delSeverity(sid){
        this.$http.get("defectSeverity/delSeverity",{
          params:{
            "severityId":sid
          }
        }).then(resp=>{
          if(resp.data.code==200){
            this.$message({
              message: resp.data.message,
              type: 'success'
            })
          }else{
            this.$message.error(resp.data.message)
          }this.getAllSeverity(1,3)
        })
      },
      selByName(){
        this.$http.post("defectSeverity/selByName",{"severityDesc":this.getByName,
                                                    "current":1,
                                                    "size":3

        }).then(resp=>{
          this.getSeverityByPage=resp.data.data.records
          this.pages=resp.data.data
        })
        }

    },
    created() {
      this.getAllSeverity(1,3)
    }
  }
</script>

<style>
</style>
